home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10975 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  39 lines

  1. Path: inforamp.net!ts28-10
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: NEWBIE : Need help with C++
  5. Date: Tue, 12 Mar 96 03:53:14 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4i2sfr$nfn@sam.inforamp.net>
  8. References: <Pine.SOL.3.91.960310214829.26563A-100000@orion>
  9. NNTP-Posting-Host: ts28-10.tor.inforamp.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <Pine.SOL.3.91.960310214829.26563A-100000@orion>,
  13.    franco <c2eyf931@Simpang.Raya> wrote:
  14. >Can someone tell me what a bucket sort is. 
  15.  
  16. Bucket sorting.
  17. Basically you put the objects in buckets, that is, hash slots that contain 
  18. more then one entry.  Thus using your example...
  19.  
  20. typedef "Some type of container class" Bucket;
  21.  
  22. main()
  23. {
  24.     const int arraysize = 5;
  25.     int a[arraysize] = {2, 27, 100, 34, 188};
  26.     Bucket b[10];
  27.     for (int i=0; i<arraysize; i++)
  28.         b[a[i]%10].Add(a[i]);
  29. };
  30.  
  31. This sorts the integers in buckets using the unit digit.  You have ten buckets 
  32. each representing the ten unit digits.  You determine which bucket they belong 
  33. to and toss them in.  Sort of like picking apples and you throw Granny Smiths 
  34. in one basket, MacIntoshes in another, overripe in another, bad in another. 
  35.  
  36. I hope this helps.
  37.  
  38. Agrivar
  39.